//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "logIn.h"
#include "selection.h"
#include "Entrance11.h"
#include "Participant11.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TentranceForm *entranceForm;

int* checked = NULL;
int flage;
//---------------------------------------------------------------------------
__fastcall TentranceForm::TentranceForm(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TentranceForm::BtnCheckInClick(TObject *Sender)
{
	//first we check if the input text has been filled
	if(this->EdtGuestID->Text == "")
	{
		ShowMessage ("You have to input an id!!");
	}
	else
	{
	int participantid = this->EdtGuestID->Text.ToInt();


	//added by Ayush############################################
	try
	{

	   AnsiString name;
	   this->ADOQuery1->SQL->Clear();
	   this->ADOQuery1->SQL->Add("SELECT * FROM guests WHERE guest_id="+AnsiString(participantid));
	   this->ADOQuery1->Open();

	   name=this->ADOQuery1->FieldByName("name")->AsString;
	   flage=this->ADOQuery1->FieldByName("check_in")->AsInteger;
	   this->ADOQuery1->Close();
	   ShowMessage("Name: "+name);


	}
	catch (Exception &exception)
	{
		ShowMessage("something went wrong");
	}
	//close by Ayush############################################

	if (participantid > 1 || participantid <= 30000000)
	 {

	   this->lblAllowed1->Caption = " You are allowed";
	   if (flage == 1 )
		{
		 ShowMessage("Allowed to check in");
		}
		else
	   {
		  ShowMessage("");
		  try
	{

	   AnsiString name;
	   this->ADOQuery1->SQL->Clear();
	   this->ADOQuery1->SQL->Add("UPDATE guests set check_in=1 WHERE guest_id="+AnsiString(participantid));
	   this->ADOQuery1->Open();

	  // name=this->ADOQuery1->FieldByName("name")->AsString;
	   flage=this->ADOQuery1->FieldByName("check_in")->AsInteger;
	   this->ADOQuery1->Close();
	   ShowMessage("Name: "+name+" flage: "+flage);


	}
	catch (Exception &exception)
	{
		ShowMessage("something went wrong");
	}

	   }

	 }
	 else
	 {
		 this->lblAllowed->Caption = " you are not allowed";
	 }

	}

}
//---------------------------------------------------------------------------


void __fastcall TentranceForm::FormClose(TObject *Sender, TCloseAction &Action)
{
   selectionForm->Close();
   logInForm->Close();
}
//---------------------------------------------------------------------------

void __fastcall TentranceForm::Button1Click(TObject *Sender)
{
 this->Visible=false;
 selectionForm->Visible=true;
}
//---------------------------------------------------------------------------




